
#include <avr/io.h>
#include <stdio.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "usartDriver.h"
#include "sramDriver.h"
#include "sramtest.h"
#include "adcDriver.h"
#include "inputDriver.h"
#include "definitions.h"
#include "oledDriver.h"
#include "menu.h"
#include "spiDriver.h"
#include "canDriver.h"

void init(void);
void writeA();

int main(void)
{
	init();
	
	//menu_main_menu();
	//canInterface_setLoopbackMode();
	canDriver_write(1,0x36,50);
	char bokstav = canDriver_read(0x36);
	printf("Lest fra register: %d\n", bokstav);

	while(1)
	{
	}	
}

void init(void)
{
	
	cli();
	sramDriver_init();
	usartDriver_init(31);
	joystickDriver_init();
	oledDriver_init();
	spiDriver_init();
	canDriver_init();
	//canInterface_setLoopbackMode();
	
	fdevopen(usartDriver_transmit, usartDriver_receive);
	
	
	sei();
}

ISR(USART0_RXC_vect){
	/*
	Interrupt if there is unread data present in the receive buffer
	*/
	usartDriver_transmit(usartDriver_receive());
}

ISR(SPI_STC_vect)
{
	char data = spiDriver_receive();
	// what do we do with the drunken data?
	usartDriver_transmit(data);
	oledDriver_write_char(data);
}